package com.woniuxy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.dao.DictionaryMapper;
import com.woniuxy.pojo.Dictionary;
import com.woniuxy.service.DictionaryService;
import com.woniuxy.util.DataGridView;
import com.woniuxy.vo.DictionaryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DictionaryServiceImpl implements DictionaryService{

    @Autowired
    private DictionaryMapper dictionaryMapper;

    @Override
    public List<Dictionary> findAllDics() {
        return dictionaryMapper.selectAllDics();
    }

    @Override
    public Dictionary findDicByName(String name) {
        return dictionaryMapper.selectDicByName(name);
    }

    @Transactional
    @Override
    public boolean AddDictionary(Dictionary dictionary){
        boolean flag = false;
        int count=this.dictionaryMapper.insertDictionary(dictionary);
        if (count > 0) {
            flag = true;
        }
        return flag;
    }

    @Override
    public List<Dictionary> findLevOne() {
        return dictionaryMapper.selectLevOne();
    }

    @Override
    public List<Dictionary> findLevTwo() {
        return dictionaryMapper.selectLevTwo();
    }

    @Override
    public List<Dictionary> findLevThree() {
        return dictionaryMapper.selectLevThree();
    }

    @Override
    public DataGridView selectDicsWithPname(DictionaryVo dictionaryVo) {
        Page<Object> page = PageHelper.startPage(dictionaryVo.getPage(), dictionaryVo.getLimit());
        List<Dictionary> dictionaryList = this.dictionaryMapper.selectDicsWithPname(dictionaryVo);
        return new DataGridView(page.getTotal(), dictionaryList);
    }

    @Override
    public List<Dictionary> queryDicsByPid(int id) {
        return dictionaryMapper.selectDicsByPid(id);
    }

    @Override
    public List<Dictionary> findAllDeptsInDic() {
        return dictionaryMapper.selectAllDeptsInDic();
    }

    @Override
    public List<Dictionary> findAllPostsInDic() {
        return dictionaryMapper.selectAllPostsInDic();
    }
}
